package com.by.controller;

import cn.hutool.core.bean.BeanUtil;
import com.by.bean.Inquiry;
import com.by.common.bean.PageBean;
import com.by.common.bean.ResultBean;
import com.by.common.controller.BaseController;
import com.by.common.group.V;
import com.by.mapper.InquiryMapper;
import com.by.query.InquiryQuery;
import com.by.service.InquiryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "货代询价")
@RequestMapping("/api")
public class InquiryController extends BaseController {
    @Autowired
    InquiryService inquiryService;
    @Autowired
    InquiryMapper inquiryMapper;
    @PostMapping("/inquiry")
    @ApiOperation("新增")
    public ResultBean save(@Validated @RequestBody Inquiry inquiry, BindingResult result){
        V.validate(result);
        int rs=inquiryService.save(inquiry);
        return saveResult(rs);
    }

    @PostMapping("/inquiry/list")
    @ApiOperation("列表查询")
    public ResultBean<PageBean> query(@RequestBody InquiryQuery inquiry){
        PageBean pageBean=inquiryService.queryByMap(BeanUtil.beanToMap(inquiry));
        return success("询价列表",pageBean);
    }


    @PutMapping("/inquiry/update")
    @ApiOperation("修改")
    public ResultBean update(@RequestBody Inquiry inquiry){
        int rs=inquiryService.update(inquiry);
        return updateResult(rs);
    }

    @ApiOperation("查询货代询价信息")
    @GetMapping("/inquiry/select")
    public ResultBean get(@RequestParam("quote_coding") String quote_coding){
        Inquiry inquiry= inquiryService.get(quote_coding);
        return success("询价信息",inquiry);
    }

}
